home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / dde / odbcncap / cts.bas < prev    next >
BASIC Source File  |  1995-10-26  |  3KB  |  101 lines

  1. Option Explicit
  2.  
  3. Function LoadMainListBox (frmForm As Form) As Integer
  4. Dim nStatus As Integer
  5. Dim sSiteId As String
  6. Dim sSiteNbr As String
  7. Dim sCity As String
  8. Dim sState As String
  9. Dim workString As String
  10. Dim sSourceSQL As String
  11. Dim i As Integer
  12. ' Hope for the best!
  13. LoadMainListBox = True
  14. frmForm!lstSites.Clear
  15.  
  16. If ghenv = 0 Then
  17.     InitializeDatabaseConnection
  18. End If
  19. If ghStmt = 0 Then
  20.     nStatus = SQLAllocStmt(ghDbc, ghStmt)
  21.     If nStatus <> SQL_SUCCESS And nStatus <> SQL_SUCCESS_WITH_INFO Then
  22.         DescribeError ghDbc, ghStmt
  23.         LoadMainListBox = False
  24.         Exit Function
  25.     End If
  26. End If
  27. sSourceSQL = "select  a.SITE_SYSGEN_ID, a.SITE_NBR, a.CITY_NAME, a.STATE_CODE"
  28. sSourceSQL = sSourceSQL & " from SITE_T a"
  29. sSourceSQL = sSourceSQL & " where a.CITY_NAME like ? "
  30. sSourceSQL = sSourceSQL & " and a.STATE_CODE = ? "
  31. sSourceSQL = sSourceSQL & " and a.SITE_SYSGEN_ID > ? "
  32.  
  33. ODBCBuildParams SQL_C_CHAR, SQL_CHAR, "San%", 4, 0, 1
  34. ODBCBuildParams SQL_C_CHAR, SQL_CHAR, "CA", 2, 0, 2
  35. ODBCBuildParams SQL_C_LONG, SQL_INTEGER, CInt(400), 5, 0, 3
  36.  
  37. nStatus = ODBCExecute(ghDbc, ghStmt, sSourceSQL, aParmList())
  38.  
  39. If nStatus <> True Then
  40.     LoadMainListBox = False
  41.     Exit Function
  42. End If
  43.  
  44.  
  45. waitcursor True
  46.  
  47. Do
  48.     nStatus = SQLFetch(ghStmt)
  49.     If nStatus = SQL_NO_DATA_FOUND Then
  50.         Exit Do
  51.     Else
  52.         If nStatus <> SQL_SUCCESS Then
  53.             DescribeError ghDbc, ghStmt
  54.             LoadMainListBox = False
  55.             Exit Do
  56.         End If
  57.     End If
  58.  
  59.     sSiteId = GetODBCWorkString(ghDbc, ghStmt, 1)
  60.     sSiteNbr = GetODBCWorkString(ghDbc, ghStmt, 2)
  61.     sCity = GetODBCWorkString(ghDbc, ghStmt, 3)
  62.     sState = GetODBCWorkString(ghDbc, ghStmt, 4)
  63.     workString = sSiteId & " " & sSiteNbr & " " & sCity & ", " & sState
  64.     frmForm!lstSites.AddItem workString
  65. Loop
  66.  
  67. nStatus = SQLFreeStmt(ghStmt, SQL_CLOSE)
  68.  
  69. sSourceSQL = "select  max(a.SITE_SYSGEN_ID)"
  70. sSourceSQL = sSourceSQL & " from SITE_T a"
  71. '
  72. ' For a non-parameterized call, you must call the
  73. ' function with zeros to reset the parameter array.
  74. '
  75. ODBCBuildParams 0, 0, 0, 0, 0, 0
  76. nStatus = ODBCExecute(ghDbc, ghStmt, sSourceSQL, aParmList())
  77.  
  78. If nStatus <> True Then
  79.     LoadMainListBox = False
  80.     GoTo FormLoad_Continue
  81. End If
  82.  
  83. nStatus = SQLFetch(ghStmt)
  84. If nStatus = SQL_SUCCESS Or nStatus = SQL_SUCCESS_WITH_INFO Then
  85.     sSiteId = GetODBCWorkString(ghDbc, ghStmt, 1)
  86.     frmForm!txtText1.Text = sSiteId
  87. Else
  88.     If nStatus <> SQL_NO_DATA_FOUND Then
  89.         DescribeError ghDbc, ghStmt
  90.         LoadMainListBox = False
  91.     End If
  92. End If
  93.  
  94. nStatus = SQLFreeStmt(ghStmt, SQL_CLOSE)
  95.  
  96. FormLoad_Continue:
  97. '*** let's clean up after ourselves and free up some memory for this statement
  98. waitcursor False
  99. End Function
  100.  
  101.